<template>
	<slot
		:controller="controller"
		:store="store"
		:model="model"
		:classNames="classNames"
		:actions="{ handleMenuClick }"
	>
		<AppMenu
			v-bind="$attrs"
			:class="classNames"
			:defaultExpands="store.defaultExpands"
			:menus="store.menus"
			:selections="store.selections"
			:mode="props.mode"
			:openViewCodeName="store.openViewCodeName"
			:counterData="props.counterData"
			:context="store.context"
			:viewParams="store.viewParams"
			@menuClick="handleMenuClick"
		>
			<template
				v-slot:[slotName]="{ item, counterData }"
				v-for="slotName of slotKeys"
			>
				<slot
					:controller="controller"
					:store="store"
					:model="model"
					:name="slotName"
					:context="context"
					:viewParams="viewParams"
					:item="item"
					:counterData="counterData"
				>
				</slot>
			</template>
		</AppMenu>
	</slot>
</template>
<script setup lang="ts">
// 基于template/src/widgets/{{appEntities}}/{{ctrls@APPMENU}}-menu/{{spinalCase ctrl.codeName}}-menu-base.vue.hbs生成
import { AppMenu } from '@components/widgets/menu';
import {
	AppMenuActionType,
	IAppMenuAbility,
	IAppMenuStore,
	IParam,
} from '@/core';
import {
	useProps,
	useBasic,
	useAction,
	useController,
} from './usr-0210019609-menu-menu-hook';

// 输入参数
const props = defineProps(useProps());

// 基础数据
const {
	controlID,
	slotKeys,
	getClassNames,
	model,
	useNavParamsBind,
	useEventBind,
} = useBasic(props);

const emit = defineEmits<{
	(
		event: 'ctrl-action',
		name: string,
		action: AppMenuActionType,
		data: IParam[]
	): void;
	(event: 'ctrl-init', name: string, data: IAppMenuAbility): void;
	(event: 'ctrl-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
//  部件样式名
const classNames = computed(() => {
	return getClassNames(props);
});

//  菜单控制器
const controller = useController(props, evt, { controlID });

useNavParamsBind(controller, props);

const store: IAppMenuStore = controller.getStore();

const { handleMenuClick } = useAction(controller);

onMounted(() => {
	controller.ctrlMounted();
});
onUnmounted(() => {
	controller.ctrlDestroy();
});
</script>
